package com.abbcc.module.admin;

import java.util.Date;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

import com.abbcc.action.BaseAction;
import com.abbcc.common.CommonConst;
import com.abbcc.models.TdLog;
import com.abbcc.service.LogService;
import com.abbcc.util.StringUtil;
import com.abbcc.util.DateUtil;

public class LogAction extends BaseAction<TdLog>{
	@Autowired
	private LogService logService;
	public String dd1;
	public String dd2;
	
	public String viewAdmin(){
		logsByType(CommonConst.LOGTYPEBYADMIN);
		return "viewAdmin";
	}
	public String viewUser(){
		logsByType(CommonConst.LOGTYPEBYUSER);
		return "viewUser";
	}
	private void logsByType(String type){
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		dc.add(Restrictions.eq("isAdmin", type)).addOrder(Order.desc("addTime"));
		if(StringUtil.isNotBlank(dd1)&&StringUtil.isNotBlank(dd2)){
			dc.add(Restrictions.between("addTime", DateUtil.strToDate(dd1), DateUtil.strToDate(dd2)));
		}else if(StringUtil.isNotBlank(dd1)){
			dc.add(Restrictions.between("addTime", DateUtil.strToDate(dd1), new Date()));
		}else if(StringUtil.isNotBlank(dd2)){
			dc.add(Restrictions.between("addTime", DateUtil.getDateStart(DateUtil.strToDate(dd2)), DateUtil.getDateEnd(DateUtil.strToDate(dd2))));
		}else{
			
		}
		pageList = logService.findPageByCriteria(dc, pageSize, startIndex);
	}
	public String getDd1() {
		return dd1;
	}
	public void setDd1(String dd1) {
		this.dd1 = dd1;
	}
	public String getDd2() {
		return dd2;
	}
	public void setDd2(String dd2) {
		this.dd2 = dd2;
	}
	
}
